#####################################################################################
# Purpose: Create Tables
# Code written by: Soeren Henn & Connor Huff
# Last updated: 2023-09-26
#####################################################################################
## This code creates ll the tables for the paper 
## "The Local Memory of Repression and Who Fights"


rm(list=ls())

## !!!!  set up location of folder here
path <- ""

dir.data <- paste(path, "\\data", sep="")
dir.output <- paste(path, "\\output", sep="")
dir.code <- paste(path, "\\code", sep="")



library(foreign)
library(plyr)         # to join
library(lfe)          # to run regressions
library(stargazer)    # to output regression tables
library(xtable)       # to print table to latex
library(dplyr)
library(ggplot2)
library(sensemakr)    # to do sensitivity analysis
library(olsrr)        # to check collinearity


#####################################################################################
############################ Table 2: Summary Statistics ############################
#####################################################################################


setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]


## restrict to variables 
data.rural <- dplyr::select(data.rural, c(excess.mortality, 
                                          log.pop61, log.pop71, log.pop81, log.pop91, log.pop01, log.pop11, 
                                          literacy.1851, literacy.1861, read.write.1901, read.write.1911, farmer.perc.1911, labourer2.perc.1911,
                                          irish.perc,
                                          enlist.pc.all, deaths.pc.all, militia.pc.post01, IRA.pc.all, 
                                          log.pop41, log.area41, pop.den.1841, literacy.1841, housing.fourth.1841, perc.cath.1841, perc.agri.1841, 
                                          potato.suit.bar, july.temperature, july.rainfall, geo.rugged, geo.distcoast, geo.distBelfast, geo.distDublin, geo.distbattles))

setwd(dir.output)
stargazer(data.rural, type = "latex",
          title="Summary Statistics of Treatment and Outcome Variables",
          covariate.labels=c("Population Loss from 1841-1851 p/c",
                             "Population 1861 (log)", "Population 1871 (log)", "Population 1881 (log)", "Population 1891 (log)", "Population 1901 (log)", "Population 1911 (log)",
                             "Read and Write 1851 p/c", "Read and Write 1861 p/c", "Read and Write 1901 p/c", "Read and Write 1911 p/c", "Farmer 1911 p/c", "Labourer 1911 p/c",
                             "Irish Speaking 1911 p/c",
                             "Enlistment WW1 p/c", "Casualties WW1 p/c", "Militia Participation p/c", "Irish Rebels Participation p/c",
                             "Population 1841 (log)", "Area 1841 (log km2)", "Population Denisty 1841", "Read and Write 1841 p/c", "Fourth Class Housing 1841 p/c", "Catholic 1841 p/c", "Agriculture 1841 p/c",
                             "Potato Suitability", "Mean July Temperature (C)", "Mean July Rainfall (mm)", "Ruggedness", "Distance to Coast (log km)", "Distance to Belfast (log km)", "Distance to Dublin (log km)", "Distance to 1798 Battle (log km)"),
          label="sumstat",
          digits=2,
          font.size="small",
          omit.summary.stat=c("p25", "p75"),
          out="table_2_sumstat.tex"
)





#####################################################################################
###### Table 3: Effect of 1841-1851 Population Loss on Conflict Participation ###### 
#####################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]


########## run regression
## WW1 Enlistment
reg.enlist <- felm(enlist.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## WW1 Casualties
reg.death <- felm(deaths.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## Militia
reg.militia <- felm(militia.pc.post01 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## IRA
reg.IRA <- felm(IRA.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="Effect of 1841-1851 Population Loss on Conflict Participation",
          keep=c("excess.mortality"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c", "Casualties WW1 p/c", "Irish Rebels p/c"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of Observation", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="table3_maineffect",
          out="table3_maineffect.tex"
)





#####################################################################################
########### Table 4: Effect of 1841-1851 Population Loss on 1918 Election ########### 
#####################################################################################

setwd(dir.data)
data.analysis <- readRDS("Analysis_Data_Const.rds")

data.analysis$log.pop41 <- log(data.analysis$population.1841)
data.analysis$log.area41 <- log(data.analysis$area.1841)

## look at treatment variable
summary(data.analysis$excess.mortality)

## correlation without controls or fixed effects
reg.share.nocon.noFE <- felm(share.SF.max ~ excess.mortality | 0 |0| Con_name, data.analysis)

## correlation without effects
reg.share.noFE <- felm(share.SF.max ~ excess.mortality  + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | 0 |0| Con_name, data.analysis)

## with fixed effects
reg.share <- felm(share.SF.max ~ excess.mortality  + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | province |0| Con_name, data.analysis)

## remove constituencies with population gain
data.loss <- data.analysis[which(data.analysis$excess.mortality>=0),]
reg.share.loss <- felm(share.SF.max ~ excess.mortality  + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | province |0| Con_name, data.loss)


########## Create Table
setwd(dir.output)
stargazer(reg.share.nocon.noFE, reg.share.noFE, reg.share, reg.share.loss, type="latex",
          title="Effect of 1841-1851 Population Loss on 1918 Election",
          keep=c("excess.mortality"),
          dep.var.labels = c("Vote Share Sinn Fein"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "No", "No", "Province", "Province"),
                           c("Unit of Observation", "Constituency", "Constituency", "Constituency", "Constituency"),
                           c("Controls", "No", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="table4_election1918",
          out="table4_election1918.tex"
)



#####################################################################################
######## Table 5: Effect of 1841-1851 Population Loss on Occupations in 1911 ######## 
#####################################################################################

setwd(dir.data)
data.barony <- readRDS("Analysis_Data_Barony.rds")


## rural only
data.rural <- data.barony[which(data.barony$rural.1841==1),]

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

reg.lit.11 <- felm(read.write.1911 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + area.1841 + pop.den.1841 + literacy.1841 + population.1841 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

reg.labourer.11 <- felm(labourer2.perc.1911 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)



setwd(dir.output)
stargazer(reg.lit.11, reg.labourer.11, type="latex",
          title="Effect of 1841-1851 Population Loss on Literacy and Occupations in 1911",
          keep=c("excess.mortality"),
          dep.var.labels = c("Perc. Read and Write", "Perc. Labourer"),
          column.labels = c("1911"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County"),
                           c("Unit of Observation", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="table5_farmer",
          out="table5_farmer.tex"
)



####################################################################################
########### Table A1: 1841-1851 Population Loss and 1841 Characteristics ########### 
####################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

reg.area <- felm(log.area41 ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.pop <- felm(log.pop41 ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.popden <- felm(pop.den.1841 ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.lit <- felm(literacy.1841 ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.forth <- felm(housing.fourth.1841 ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.cath <- felm(perc.cath.1841 ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.agri <- felm(perc.agri.1841 ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.potato <- felm(potato.suit.bar ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.temp <- felm(july.temperature ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.rain <- felm(july.rainfall ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.rugged <- felm(geo.rugged ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.coast <- felm(geo.distcoast ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.Belfast <- felm(geo.distBelfast ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.Dublin <- felm(geo.distDublin ~ excess.mortality | county_id |0| GEOG_ID, data.rural)
reg.1798 <- felm(geo.distbattles ~ excess.mortality | county_id |0| GEOG_ID, data.rural)

setwd(dir.output)
stargazer(reg.area, reg.pop, reg.popden, reg.lit, reg.forth, reg.cath, reg.agri, reg.potato, reg.temp, reg.rain, reg.rugged, reg.coast, reg.Belfast, reg.Dublin, reg.1798, type="latex",
          title="1841-1851 Population Loss and 1841 Characteristics",
          keep=c("excess.mortality"),
          dep.var.labels = c("Area", "Population", "PopDens", "Literacy", "Fourth Class", "Catholic", "Agriculture", "Potato Suit", "July Temp", "July Rain", "Rugged", "Dist Coast", "Dist Belfast", "Dist Dublin", "Dist 1798"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County", "County", "County", "County", "County", "County", "County", "County", "County", "County"),
                           c("Unit of Observation", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "No", "No", "No", "No", "No", "No", "No", "No", "No", "No", "No", "No", "No")),
          font.size="tiny",
          notes.label = "Robust s.e. in parentheses",
          label="tablea1_determinants",
          flip=T,
          out="tablea1_determinants.tex"
)


#####################################################################################
############ Table A2: Effect of 1841-1851 Population Loss on Population ############ 
#####################################################################################
setwd(dir.data)
data.barony <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.barony[which(data.barony$rural.1841==1),]

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]


reg.61 <- felm(log.pop61 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + area.1841 + pop.den.1841 + literacy.1841 + population.1841 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.71 <- felm(log.pop71 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + area.1841 + pop.den.1841 + literacy.1841 + population.1841 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.81 <- felm(log.pop81 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + area.1841 + pop.den.1841 + literacy.1841 + population.1841 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.91 <- felm(log.pop91 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + area.1841 + pop.den.1841 + literacy.1841 + population.1841 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.01 <- felm(log.pop01 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + area.1841 + pop.den.1841 + literacy.1841 + population.1841 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.11 <- felm(log.pop11 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + area.1841 + pop.den.1841 + literacy.1841 + population.1841 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)


setwd(dir.output)
stargazer(reg.61, reg.71, reg.81, reg.91, reg.01, reg.11, type="latex",
          title="Effect of 1841-1851 Population Loss on Population",
          keep=c("excess.mortality"),
          dep.var.labels = c("Barony Population"),
          column.labels = c("1861", "1871", "1881", "1891", "1901", "1911"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County", "County", "County"),
                           c("Unit of Observation", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea2_population",
          out="tablea2_population.tex"
)

#####################################################################################
## Table A3: Effect of 1841-1851 Population Loss on Farmers, Irish language and Catholicism 1911 #
#####################################################################################

setwd(dir.data)
data.barony <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.barony[which(data.barony$rural.1841==1),]

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

reg.irish.11 <- felm(irish.perc ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.cath.11 <- felm(catholic.1911 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.farmer.11 <- felm(farmer.perc.1911 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)


setwd(dir.output)
stargazer(reg.farmer.11, reg.irish.11, reg.cath.11, type="latex",
          title="Effect of 1841-1851 Population Loss on Farmers, Irish language and Catholicism 1911",
          keep=c("excess.mortality"),
          dep.var.labels = c("Perc. Irish Language", "Perc. Catholic"),
          column.labels = c("1911", "1911"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County"),
                           c("Unit of Observation", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea3_irish",
          out="tablea3_irish.tex"
)




#####################################################################################
############# Table A4: Effect of 1841-1851 Population Loss on Literacy #############
#####################################################################################

setwd(dir.data)
data.barony <- readRDS("Analysis_Data_Barony.rds")


## rural only
data.rural <- data.barony[which(data.barony$rural.1841==1),]

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

reg.lit.51 <- felm(literacy.1851 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + area.1841 + pop.den.1841 + literacy.1841 + population.1841 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.lit.61 <- felm(literacy.1861 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + area.1841 + pop.den.1841 + literacy.1841 + population.1841 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.lit.01 <- felm(read.write.1901 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + area.1841 + pop.den.1841 + literacy.1841 + population.1841 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.lit.11 <- felm(read.write.1911 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + area.1841 + pop.den.1841 + literacy.1841 + population.1841 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

setwd(dir.output)
stargazer(reg.lit.51, reg.lit.61, reg.lit.01, reg.lit.11, type="latex",
          title="Effect of 1841-1851 Population Loss on Literacy",
          keep=c("excess.mortality"),
          dep.var.labels = c("Percentage Read and Write "),
          column.labels = c("1851", "1861", "1901", "1911"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County", "County", "County"),
                           c("Unit of observation", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea4_literacy",
          out="tablea4_literacy.tex"
)

#####################################################################################
####### Table A5: Effect of 1841-1851 Population Loss on Literacy by Religion ####### 
#####################################################################################

setwd(dir.data)
data.barony <- readRDS("Analysis_Data_Barony.rds")


## rural only
data.rural <- data.barony[which(data.barony$rural.1841==1),]

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

## literacy by religion
reg.lit.11.c <- felm(literacy.catholic.1911 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.lit.11.nc <- felm(literacy.noncatholic.1911 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

setwd(dir.output)
stargazer(reg.lit.11.c, reg.lit.11.nc, type="latex",
          title="Effect of 1841-1851 Population Loss on Literacy by Religion",
          keep=c("excess.mortality"),
          dep.var.labels = c("Percentage Read and Write 1911"),
          column.labels = c("Catholic", "Non-Catholic"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County", "County", "County"),
                           c("Unit of observation", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea5_literacy_religion",
          out="tablea5_literacy_religion.tex"
)


#######################################################################################################
## Table A6: Effect of 1841-1851 Excess Mortality on Conflict Participation Including Baronies with Population Loss ## 
#######################################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## fix one outlier
data.rural$excess.mortality[which(data.rural$excess.mortality< -0.18)] <- -0.18

########## run regression
## WW1 Enlistment
reg.enlist <- felm(enlist.pc.all ~ excess.mortality + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## WW1 Casualties
reg.death <- felm(deaths.pc.all ~ excess.mortality + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## Militia
reg.militia <- felm(militia.pc.all01 ~ excess.mortality + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## IRA
reg.IRA <- felm(IRA.pc.all ~ excess.mortality + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="Effect of 1841-1851 Population Loss on Conflict Participation Including Baronies with Population Gain",
          keep=c("excess.mortality"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c", "Casualties WW1 p/c", "IRA p/c"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of  observation", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea6_main_gain",
          out="tablea6_main_gain.tex"
)


#####################################################################################
###### Table A7: Main Effect But No Controls ###### 
#####################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

########## run regression
## WW1 Enlistment
reg.enlist <- felm(enlist.pc.all ~ excess.mortality | county_id |0| GEOG_ID, data.rural)

## WW1 Casualties
reg.death <- felm(deaths.pc.all ~ excess.mortality | county_id |0| GEOG_ID, data.rural)

## Militia
reg.militia <- felm(militia.pc.post01 ~ excess.mortality  | county_id |0| GEOG_ID, data.rural)

## IRA
reg.IRA <- felm(IRA.pc.all ~ excess.mortality  | county_id |0| GEOG_ID, data.rural)

########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="Effect of 1841-1851 Population Loss on Conflict Participation Without Controls",
          keep=c("excess.mortality"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c", "Casualties WW1 p/c", "Irish Rebels p/c"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of  observation", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "No", "No", "No", "No")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea7_nocontrols",
          out="tablea7_nocontrols"
)



#####################################################################################
## Table A8: Effect of 1841-1851 Excess Mortality on Conflict Participation No density ## 
#####################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

########## Test collinearity
reg.enlist <- lm(enlist.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin , data.rural)
ols_coll_diag(reg.enlist)
## VIF for log.area41 + pop.den.1841 + log.pop41 is over 10
reg.enlist <- lm(enlist.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin , data.rural)
ols_coll_diag(reg.enlist)
## now no VIF is over 10

########## run regression
## WW1 Enlistment
reg.enlist <- felm(enlist.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41  + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## WW1 Casualties
reg.death <- felm(deaths.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41  + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## Militia
reg.militia <- felm(militia.pc.post01 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41  + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## IRA
reg.IRA <- felm(IRA.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41  + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="Effect of 1841-1851 Population Loss on Conflict Participation",
          keep=c("excess.mortality"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c", "Casualties WW1 p/c", "Irish Rebels p/c"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of  observation", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea8_nodensity",
          out="tablea8_nodensity.tex"
)



#####################################################################################
###### Table A9: Main Effect But Including Barony Valuation as Control ###### 
#####################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

########## run regression
## WW1 Enlistment
reg.enlist <- felm(enlist.pc.all ~ excess.mortality + geo.distbattles + goodspeed.valuation + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## WW1 Casualties
reg.death <- felm(deaths.pc.all ~ excess.mortality + geo.distbattles + goodspeed.valuation + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## Militia
reg.militia <- felm(militia.pc.post01 ~ excess.mortality + geo.distbattles + goodspeed.valuation + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## IRA
reg.IRA <- felm(IRA.pc.all ~ excess.mortality + perc.cath.1841 + geo.distbattles + goodspeed.valuation + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="Effect of 1841-1851 Population Loss on Conflict Participation including Valuation as Control",
          keep=c("excess.mortality"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c", "Casualties WW1 p/c", "Irish Rebels p/c"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of  observation", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea9_valuation",
          out="tablea9_valuation.tex"
)

#####################################################################################
## Table A10: Effect of 1841-1851 Population Loss on Conflict Participation Controlling for 1798 Battle Indicator ##
#####################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

########## whether barony
## WW1 Enlistment
reg.enlist <- felm(enlist.pc.all ~ excess.mortality + geo.baronybattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## WW1 Casualties
reg.death <- felm(deaths.pc.all ~ excess.mortality + geo.baronybattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## Militia
reg.militia <- felm(militia.pc.post01 ~ excess.mortality + geo.baronybattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## IRA
reg.IRA <- felm(IRA.pc.all ~ excess.mortality + geo.baronybattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="Effect of 1841-1851 Population Loss on Conflict Participation",
          keep=c("excess.mortality"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c", "Casualties WW1 p/c", "Irish Rebels p/c"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of  observation", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea10_1798b",
          out="tablea10_1798b.tex"
)


############################################################################
## Table A11: Effect of 1841-1851 Population Loss on Conflict Participation Controlling for Longitude and Lattitude ##
############################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]


########## run regression
## WW1 Enlistment
reg.enlist <- felm(enlist.pc.all ~ excess.mortality + lon.x + lat.x + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## WW1 Casualties
reg.death <- felm(deaths.pc.all ~ excess.mortality + lon.x + lat.x + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## Militia
reg.militia <- felm(militia.pc.post01 ~ excess.mortality + lon.x + lat.x + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## IRA
reg.IRA <- felm(IRA.pc.all ~ excess.mortality + lon.x + lat.x + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="Effect of 1841-1851 Population Loss on Conflict Participation Controlling for Longitude and Lattitude",
          keep=c("excess.mortality"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c", "Casualties WW1 p/c", "Irish Rebels p/c"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of  observation", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea11_longlat",
          out="tablea11_longlat.tex"
)

#####################################################################################
## Table A12: Effect of 1841-1851 Population Loss on Conflict Participation Without Climate Controls ## 
#####################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]


########## run regression
## WW1 Enlistment
reg.enlist <- felm(enlist.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841  +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## WW1 Casualties
reg.death <- felm(deaths.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## Militia
reg.militia <- felm(militia.pc.post01 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## IRA
reg.IRA <- felm(IRA.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841  +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

summary(reg.enlist)
summary(reg.death)
summary(reg.militia)
summary(reg.IRA)


########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="Effect of 1841-1851 Population Loss on Conflict Participation Without Climate Controls",
          keep=c("excess.mortality"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c", "Casualties WW1 p/c", "Irish Rebels p/c"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of  observation", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea12_noclimate",
          out="tablea12_noclimate.tex"
)



#####################################################################################
### Table A13: Effect of 1841-1851 Population Loss on Total Conflict Participation ## 
#####################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

## replace missing with zero
data.rural$militia.perbarony.post[is.na(data.rural$militia.perbarony.post)] <- 0
data.rural$enlist.perbarony[is.na(data.rural$enlist.perbarony)] <- 0
data.rural$deaths.perbarony[is.na(data.rural$deaths.perbarony)] <- 0
data.rural$IRA.perbarony[is.na(data.rural$IRA.perbarony)] <- 0


########## run regression
## WW1 Enlistment
reg.enlist <- felm(enlist.perbarony ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## WW1 Casualties
reg.death <- felm(deaths.perbarony ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## Militia
reg.militia <- felm(militia.perbarony.post ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

## IRA
reg.IRA <- felm(IRA.perbarony ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="Effect of 1841-1851 Population Loss on Total Conflict Participation",
          keep=c("excess.mortality"),
          dep.var.labels = c("Militia count", "Enlistment WW1 count", "Casualties WW1 count", "Irish Rebels count"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of  observation", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea13_total",
          out="tablea13_total.tex"
)



######################################################################################
## Table A14: Effect of 1841-1851 Population Loss on Parish Level Economic Outcomes ##
######################################################################################

## load data
setwd(dir.data)
data.parish <- readRDS("Analysis_Data_Parish.rds")

## rural only
data.rural <- data.parish[which(data.parish$rural==1),]

data.rural$log.area41 <- log(data.rural$area_km)

data.rural$log.pop41 <- log(data.rural$population.1841)
data.rural$log.pop11 <- log(data.rural$population.1911)

## Fixed effects (temporary solution)
data.rural$fixed_effects <- paste(data.rural$COUNTY, data.rural$BARONY, sep="-")

########## Analysis
## main
reg.pop <- felm(log.pop11 ~ exmort + geo.distbattles + perc.cath.1834 + log.pop41 + pop.den.1841 + housing.fourth.1841 + literacy.1841 + agriculture.perc.1841 + log.area41 + potato.suit.bar + july.temperature + july.rainfall + geo.distcoast + geo.rugged + geo.distDublin + geo.distBelfast | fixed_effects |0| GEOG_ID, data.rural)
reg.read <- felm(read.write.1911 ~ exmort + geo.distbattles + perc.cath.1834 + log.pop41 + pop.den.1841 + housing.fourth.1841 + literacy.1841 + agriculture.perc.1841 + log.area41 + potato.suit.bar + july.temperature + july.rainfall + geo.distcoast + geo.rugged + geo.distDublin + geo.distBelfast | fixed_effects |0| GEOG_ID, data.rural)
reg.irish <- felm(irish.perc ~ exmort + geo.distbattles + perc.cath.1834 + log.pop41 + pop.den.1841 + housing.fourth.1841 + literacy.1841 + agriculture.perc.1841 + log.area41 + potato.suit.bar + july.temperature + july.rainfall + geo.distcoast + geo.rugged + geo.distDublin + geo.distBelfast | fixed_effects |0| GEOG_ID, data.rural)
reg.farmer <- felm(farmer.perc.1911 ~ exmort + geo.distbattles + perc.cath.1834 + log.pop41 + pop.den.1841 + housing.fourth.1841 + literacy.1841 + agriculture.perc.1841 + log.area41 + potato.suit.bar + july.temperature + july.rainfall + geo.distcoast + geo.rugged + geo.distDublin + geo.distBelfast | fixed_effects |0| GEOG_ID, data.rural)
reg.labourer <- felm(gen.labourer2 ~ exmort + geo.distbattles + perc.cath.1834 + log.pop41 + pop.den.1841 + housing.fourth.1841 + literacy.1841 + agriculture.perc.1841 + log.area41 + potato.suit.bar + july.temperature + july.rainfall + geo.distcoast + geo.rugged + geo.distDublin + geo.distBelfast | fixed_effects |0| GEOG_ID, data.rural)

setwd(dir.output)
stargazer(reg.pop, reg.read, reg.irish, reg.farmer, reg.labourer, type="latex",
          title="Effect of 1841-1851 Population Loss on Parish Level Economic Outcomes",
          keep=c("exmort"),
          dep.var.labels = c("Population", "Literacy", "Irish Language", "Perc. Farmer", "Perc. Labourer"),
          column.labels = c("1911", "1911", "1911", "1911", "1911"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony"),
                           c("Unit of  observation", "Parish", "Parish", "Parish", "Parish", "Parish", "Parish"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea14_parish_econ",
          out="tablea14_parish_econ.tex"
)



######################################################################################
## Table A15: Effect of 1841-1851 Population Loss on Parish Level Conflict Outcomes ##
######################################################################################
## load data
setwd(dir.data)
data.parish <- readRDS("Analysis_Data_Parish.rds")

## rural only
data.rural <- data.parish[which(data.parish$rural==1),]

data.rural$log.area41 <- log(data.rural$area_km)

data.rural$log.pop41 <- log(data.rural$population.1841)
data.rural$log.pop11 <- log(data.rural$population.1911)

## Fixed effects (temporary solution)
data.rural$fixed_effects <- paste(data.rural$COUNTY, data.rural$BARONY, sep="-")

reg.militia <- felm(militia.pc.post01 ~ exmort + geo.distbattles + perc.cath.1834 + log.pop41 + pop.den.1841 + housing.fourth.1841 + literacy.1841 + agriculture.perc.1841 + log.area41 + potato.suit.bar + july.temperature + july.rainfall + geo.distcoast + geo.rugged + geo.distDublin + geo.distBelfast | fixed_effects |0| GEOG_ID, data.rural)
reg.enlist <- felm(enlist.pc.all ~ exmort + geo.distbattles + perc.cath.1834 + log.pop41 + pop.den.1841 + housing.fourth.1841 + literacy.1841 + agriculture.perc.1841 + log.area41 + potato.suit.bar + july.temperature + july.rainfall + geo.distcoast + geo.rugged + geo.distDublin + geo.distBelfast | fixed_effects |0| GEOG_ID, data.rural)


setwd(dir.output)
stargazer(reg.militia, reg.enlist, type="latex",
          title="Effect of 1841-1851 Population Loss on Parish Level Conflict Outcomes",
          keep=c("exmort"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "Barony", "Barony", "Barony", "Barony", "Barony", "Barony"),
                           c("Unit of  observation", "Parish", "Parish", "Parish", "Parish", "Parish", "Parish"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea15_parish_conflict",
          out="tablea15_parish_conflict.tex"
)


#####################################################################################
## Table A16: Effect of 1841-1851 Population Loss on Conflict Participation Conley Standard Errors ## 
#####################################################################################
## load conley code https://static1.squarespace.com/static/558eff8ce4b023b6b855320a/t/573bd63745bf21da74c080a8/1463539276997/ARE_212_Section_10.pdf
setwd(dir.code)
setwd("functions")
source("burlingconley.R")

tbldfGrabber <- function(data, varnames) {
  matrixObject <- data %>%
    select_(.dots = varnames) %>%
    as.matrix()
}

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

## create dummies for county fixed effects
library(dummies)
data.new <- cbind(data.rural, dummy(data.rural$county_id, sep = "."))


########## run regression
## WW1 Enlistment
reg.enlist <- felm(enlist.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| lon.x + lat.x, data.rural, keepCX = TRUE)

reg.enlist.Conley <- olsConley(data.new, "enlist.pc.all", c("excess.mortality", "geo.distbattles", "perc.cath.1841", 
                                                            "perc.agri.1841", "log.area41", "pop.den.1841", "literacy.1841", 
                                                            "log.pop41", "housing.fourth.1841", "potato.suit.bar", 
                                                            "july.temperature", "july.rainfall", "geo.rugged", 
                                                            "geo.distcoast", "geo.distBelfast", "geo.distDublin", 
                                                            "data.rural.CC01", "data.rural.CC02", "data.rural.CC03", 
                                                            "data.rural.CC04", "data.rural.CC05", "data.rural.LC01", 
                                                            "data.rural.LC02", "data.rural.LC03", "data.rural.LC04",          
                                                            "data.rural.LC05", "data.rural.LC06", "data.rural.LC07",           
                                                            "data.rural.LC08", "data.rural.LC09", "data.rural.LC10",          
                                                            "data.rural.LC11", "data.rural.LC12", "data.rural.MC01",          
                                                            "data.rural.MC02", "data.rural.MC03", "data.rural.MC04",          
                                                            "data.rural.MC05", "data.rural.MC06", "data.rural.UC01",          
                                                            "data.rural.UC02", "data.rural.UC03", "data.rural.UC04",          
                                                            "data.rural.UC05", "data.rural.UC06", "data.rural.UC07",          
                                                            "data.rural.UC08", "data.rural.UC09"), "lat.x", "lon.x", 100)
#View(reg.enlist.Conley)
reg.enlist[["cse"]][["excess.mortality"]] <- reg.enlist.Conley[["conleySE"]][["excess.mortality"]]

## WW1 Casualties
reg.death <- felm(deaths.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| lon.x + lat.x, data.rural)

reg.death.Conley <- olsConley(data.new, "deaths.pc.all", c("excess.mortality", "geo.distbattles", "perc.cath.1841", 
                                                           "perc.agri.1841", "log.area41", "pop.den.1841", "literacy.1841", 
                                                           "log.pop41", "housing.fourth.1841", "potato.suit.bar", 
                                                           "july.temperature", "july.rainfall", "geo.rugged", 
                                                           "geo.distcoast", "geo.distBelfast", "geo.distDublin", 
                                                           "data.rural.CC01", "data.rural.CC02", "data.rural.CC03", 
                                                           "data.rural.CC04", "data.rural.CC05", "data.rural.LC01", 
                                                           "data.rural.LC02", "data.rural.LC03", "data.rural.LC04",          
                                                           "data.rural.LC05", "data.rural.LC06", "data.rural.LC07",           
                                                           "data.rural.LC08", "data.rural.LC09", "data.rural.LC10",          
                                                           "data.rural.LC11", "data.rural.LC12", "data.rural.MC01",          
                                                           "data.rural.MC02", "data.rural.MC03", "data.rural.MC04",          
                                                           "data.rural.MC05", "data.rural.MC06", "data.rural.UC01",          
                                                           "data.rural.UC02", "data.rural.UC03", "data.rural.UC04",          
                                                           "data.rural.UC05", "data.rural.UC06", "data.rural.UC07",          
                                                           "data.rural.UC08", "data.rural.UC09"), "lat.x", "lon.x", 100)
#View(reg.death.Conley)
reg.death[["cse"]][["excess.mortality"]] <- reg.death.Conley[["conleySE"]][["excess.mortality"]]

reg.death[["coefficients"]][[1]] / reg.death[["cse"]][["excess.mortality"]]


## Militia
reg.militia <- felm(militia.pc.post01 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| lon.x + lat.x, data.rural)

reg.militia.Conley <- olsConley(data.new, "militia.pc.post01", c("excess.mortality", "geo.distbattles", "perc.cath.1841", 
                                                                 "perc.agri.1841", "log.area41", "pop.den.1841", "literacy.1841", 
                                                                 "log.pop41", "housing.fourth.1841", "potato.suit.bar", 
                                                                 "july.temperature", "july.rainfall", "geo.rugged", 
                                                                 "geo.distcoast", "geo.distBelfast", "geo.distDublin", 
                                                                 "data.rural.CC01", "data.rural.CC02", "data.rural.CC03", 
                                                                 "data.rural.CC04", "data.rural.CC05", "data.rural.LC01", 
                                                                 "data.rural.LC02", "data.rural.LC03", "data.rural.LC04",          
                                                                 "data.rural.LC05", "data.rural.LC06", "data.rural.LC07",           
                                                                 "data.rural.LC08", "data.rural.LC09", "data.rural.LC10",          
                                                                 "data.rural.LC11", "data.rural.LC12", "data.rural.MC01",          
                                                                 "data.rural.MC02", "data.rural.MC03", "data.rural.MC04",          
                                                                 "data.rural.MC05", "data.rural.MC06", "data.rural.UC01",          
                                                                 "data.rural.UC02", "data.rural.UC03", "data.rural.UC04",          
                                                                 "data.rural.UC05", "data.rural.UC06", "data.rural.UC07",          
                                                                 "data.rural.UC08", "data.rural.UC09"), "lat.x", "lon.x", 100)
#View(reg.militia.Conley)
reg.militia[["cse"]][["excess.mortality"]] <- reg.militia.Conley[["conleySE"]][["excess.mortality"]]

## IRA
reg.IRA <- felm(IRA.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| lon.x + lat.x, data.rural)

reg.IRA.Conley <- olsConley(data.new, "IRA.pc.all", c("excess.mortality", "geo.distbattles", "perc.cath.1841", 
                                                      "perc.agri.1841", "log.area41", "pop.den.1841", "literacy.1841", 
                                                      "log.pop41", "housing.fourth.1841", "potato.suit.bar", 
                                                      "july.temperature", "july.rainfall", "geo.rugged", 
                                                      "geo.distcoast", "geo.distBelfast", "geo.distDublin", 
                                                      "data.rural.CC01", "data.rural.CC02", "data.rural.CC03", 
                                                      "data.rural.CC04", "data.rural.CC05", "data.rural.LC01", 
                                                      "data.rural.LC02", "data.rural.LC03", "data.rural.LC04",          
                                                      "data.rural.LC05", "data.rural.LC06", "data.rural.LC07",           
                                                      "data.rural.LC08", "data.rural.LC09", "data.rural.LC10",          
                                                      "data.rural.LC11", "data.rural.LC12", "data.rural.MC01",          
                                                      "data.rural.MC02", "data.rural.MC03", "data.rural.MC04",          
                                                      "data.rural.MC05", "data.rural.MC06", "data.rural.UC01",          
                                                      "data.rural.UC02", "data.rural.UC03", "data.rural.UC04",          
                                                      "data.rural.UC05", "data.rural.UC06", "data.rural.UC07",          
                                                      "data.rural.UC08", "data.rural.UC09"), "lat.x", "lon.x", 100)
#View(reg.IRA.Conley)
reg.IRA[["cse"]][["excess.mortality"]] <- reg.IRA.Conley[["conleySE"]][["excess.mortality"]]
reg.IRA[["coefficients"]][[1]] / reg.IRA[["cse"]][["excess.mortality"]]


########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="Effect of 1841-1851 Population Loss on Conflict Participation Conley Standard Errors",
          keep=c("excess.mortality"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c", "Casualties WW1 p/c", "Irish Rebels p/c"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of  observation", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea16_conley",
          out="tablea16_conley.tex"
)

#####################################################################################
## Table A17: Effect of 1841-1851 Population Loss on Conflict Participation in Irish Rebel Forces ## 
#####################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$IRA.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]


reg.IRA <- felm(IRA.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.IRA.2434 <- felm(IRA.pc.all.2434 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)
reg.ER.a <- felm(IRA.pc.ERa ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | county_id |0| GEOG_ID, data.rural)

########## Create Table
setwd(dir.output)
stargazer(reg.IRA, reg.IRA.2434, reg.ER.a, type="latex",
          title="Effect of 1841-1851 Population Loss on Conflict Participation Conley Standard Errors",
          keep=c("excess.mortality"),
          dep.var.labels = c("Pensions p/c", "Awarded 24/34", "Easter Rising p/c"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of Observation", "Barony", "Barony", "Barony", "Barony"),
                           c("Controls", "Yes", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea17_complete_ira",
          out="tablea17_complete_ira.tex"
)



#####################################################################################
##### Table A18: Effect of 1841-1851 Population Loss on 1918 Election Robustness ####
#####################################################################################


setwd(dir.data)
data.analysis <- readRDS("Analysis_Data_Const.rds")
data.analysis$log.pop41 <- log(data.analysis$population.1841)
data.analysis$log.area41 <- log(data.analysis$area.1841)
## look at treatment variable
summary(data.analysis$excess.mortality)

reg.share <- felm(share.SF.max ~ excess.mortality  + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | province |0| Con_name, data.analysis)

reg.share.remove <- felm(share.SF.remove ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | province |0| Con_name, data.analysis)

reg.share.100 <- felm(share.SF.100 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin | province |0| Con_name, data.analysis)


########## Create Table
setwd(dir.output)
stargazer(reg.share, reg.share.remove, reg.share.100, type="latex",
          title="Effect of 1841-1851 Population Loss on 1918 Election Robustness",
          keep=c("excess.mortality"),
          dep.var.labels = c("Vote Share Sinn Fein"),
          covariate.labels=c("Population Loss 1841-1851"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "Province", "Province", "Province"),
                           c("Unit of  observation", "Constituency", "Constituency", "Constituency"),
                           c("Controls", "Yes", "Yes", "Yes")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea18_election1918_robust",
          out="tablea18_election1918_robust.tex"
)



#####################################################################################
######################## Table A19: Correlates of Conflict 1841 ####################### 
#####################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

########## run regression
## WW1 Enlistment
reg.enlist <- felm(enlist.pc.all ~ perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + geo.distbattles | county_id |0| GEOG_ID, data.rural)

## WW1 Casualties
reg.death <- felm(deaths.pc.all ~ perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + geo.distbattles | county_id |0| GEOG_ID, data.rural)

## Militia
reg.militia <- felm(militia.pc.all01 ~ perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + geo.distbattles | county_id |0| GEOG_ID, data.rural)

## IRA
reg.IRA <- felm(IRA.pc.all ~ perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + geo.distbattles | county_id |0| GEOG_ID, data.rural)

########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="1841 Correlates of Conflict Participation",
          keep=c("perc.cath.1841", "perc.agri.1841", "log.area41", "pop.den.1841", "literacy.1841", "log.pop11", "housing.fourth.1841", "potato.suit.bar", "july.temperature", "july.rainfall", "geo.rugged", "geo.distcoast", "geo.distBelfast", "geo.distDublin", "geo.distbattles"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c", "Casualties WW1 p/c", "Irish Rebels p/c"),
          covariate.labels=c("Perc. Catholic", "Perc. Farmer", "Area", "Pop Density", "Literacy", "Population", "Fourth Housing", "Potato Suitability", "July Temp", "July Rain", "Ruggedness", "Dist Coast", "Dist Belfast", "Dist Dublin", "Dist 1798 Battle"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of  observation", "Barony", "Barony", "Barony", "Barony")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea19_correlates1841",
          out="tablea19_correlates1841.tex"
)



#####################################################################################
######################## Table A20: Correlates of Conflict 1911 #######################
#####################################################################################

setwd(dir.data)
data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

########## run regression
## WW1 Enlistment
reg.enlist <- felm(enlist.pc.all ~ catholic.1911 + irish.perc + farmer.perc.1911 + labourer2.perc.1911 + read.write.1911 + male.perc.1911 + log.pop11 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + geo.distbattles | county_id |0| GEOG_ID, data.rural)

## WW1 Casualties
reg.death <- felm(deaths.pc.all ~ catholic.1911 + irish.perc + farmer.perc.1911 + labourer2.perc.1911 + read.write.1911 + male.perc.1911 + log.pop11 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + geo.distbattles | county_id |0| GEOG_ID, data.rural)

## Militia
reg.militia <- felm(militia.pc.all01 ~ catholic.1911 + irish.perc + farmer.perc.1911 + labourer2.perc.1911 + read.write.1911 + male.perc.1911 + log.pop11 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + geo.distbattles | county_id |0| GEOG_ID, data.rural)

## IRA
reg.IRA <- felm(IRA.pc.all ~ catholic.1911 + irish.perc + farmer.perc.1911 + labourer2.perc.1911 + read.write.1911 + male.perc.1911 + log.pop11 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + geo.distbattles | county_id |0| GEOG_ID, data.rural)

########## Create Table
setwd(dir.output)
stargazer(reg.militia, reg.enlist, reg.death, reg.IRA, type="latex",
          title="1911 Correlates of Conflict Participation",
          keep=c("catholic.1911", "irish.perc", "farmer.perc.1911", "labourer2.perc.1911", "read.write.1911", "male.perc.1911", "log.pop11", "potato.suit.bar", "july.temperature", "july.rainfall", "geo.rugged", "geo.distcoast", "geo.distBelfast", "geo.distDublin", "geo.distbattles"),
          dep.var.labels = c("Militia p/c", "Enlistment WW1 p/c", "Casualties WW1 p/c", "Irish Rebels p/c"),
          covariate.labels=c("Perc. Catholic", "Perc. Irish Speak", "Perc. Farmer", "Perc. Labourer", "Literacy", "Perc. Male", "Population", "Potato Suitability", "July Temp", "July Rain", "Ruggedness", "Dist Coast", "Dist Belfast", "Dist Dublin", "Dist 1798 Battle"),
          keep.stat=c("n","adj.rsq"),
          add.lines = list(c("Fixed effects", "County", "County", "County", "County"),
                           c("Unit of  observation", "Barony", "Barony", "Barony", "Barony")),
          font.size="small",
          notes.label = "Robust s.e. in parentheses",
          label="tablea20_correlates1911",
          out="tablea20_correlates1911.tex"
)





##################################################################
###################### Table A21: Sensitivity ######################
##################################################################

setwd(dir.data)

data.merged <- readRDS("Analysis_Data_Barony.rds")

## rural only
data.rural <- data.merged[which(data.merged$rural.1841==1),]
summary(data.rural$enlist.pc.all)

## only keep baronies with population loss
data.rural <- data.rural[which(data.rural$excess.mortality>=0),]

reg.enlist <- lm(enlist.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + factor(county_id), data=data.rural, na.action=na.omit)
summary(reg.enlist)
enlist.sensitivity <- sensemakr(model = reg.enlist, 
                                treatment = "excess.mortality",
                                benchmark_covariates = "perc.cath.1841",
                                kd = c(5,15,25),
                                #ky = 1:3, 
                                q = 1,
                                alpha = 0.05, 
                                reduce = TRUE)
summary(enlist.sensitivity)
plot(enlist.sensitivity)
setwd(dir.output)
pdf("fig_sensitivity_enlist.pdf")
plot(enlist.sensitivity)
dev.off()

## casualties
reg.death <- lm(deaths.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + factor(county_id), data=data.rural, na.action=na.omit)

death.sensitivity <- sensemakr(model = reg.death, 
                               treatment = "excess.mortality",
                               benchmark_covariates = "perc.cath.1841",
                               kd = c(5,15,25),
                               #ky = 1:3, 
                               q = 1,
                               alpha = 0.05, 
                               reduce = TRUE)
summary(death.sensitivity)
setwd(dir.output)
pdf("fig_sensitivity_death.pdf")
plot(death.sensitivity)
dev.off()

## Militia
reg.militia <- lm(militia.pc.post01 ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + factor(county_id), data=data.rural, na.action=na.omit)

militia.sensitivity <- sensemakr(model = reg.militia, 
                                 treatment = "excess.mortality",
                                 benchmark_covariates = "perc.cath.1841",
                                 kd = c(5,15,25,50),
                                 #ky = 1:3, 
                                 q = 1,
                                 alpha = 0.05, 
                                 reduce = TRUE)
summary(militia.sensitivity)
setwd(dir.output)
pdf("fig_sensitivity_militia.pdf")
plot(militia.sensitivity)
dev.off()

## IRA

reg.IRA <- lm(IRA.pc.all ~ excess.mortality + geo.distbattles + perc.cath.1841 + perc.agri.1841 + log.area41 + pop.den.1841 + literacy.1841 + log.pop41 + housing.fourth.1841 + potato.suit.bar + july.temperature + july.rainfall +  geo.rugged + geo.distcoast + geo.distBelfast + geo.distDublin + factor(county_id), data=data.rural, na.action=na.omit)

IRA.sensitivity <- sensemakr(model = reg.IRA, 
                             treatment = "excess.mortality",
                             benchmark_covariates = "perc.cath.1841",
                             kd = c(5,10,15),
                             #ky = 1:3, 
                             q = 1,
                             alpha = 0.05, 
                             reduce = TRUE)
summary(IRA.sensitivity)
plot(IRA.sensitivity)
setwd(dir.output)
pdf("fig_sensitivity_IRA.pdf")
plot(IRA.sensitivity)
dev.off()